home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Src / LINEconsole / msgs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  29.1 KB  |  1,340 lines

  1. /* msgs.c: msgs routines */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Src/LINEconsole/RCS/msgs.c,v 6.0 1991/12/18 20:26:30 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Src/LINEconsole/RCS/msgs.c,v 6.0 1991/12/18 20:26:30 jpo Rel $
  9.  *
  10.  * $Log: msgs.c,v $
  11.  * Revision 6.0  1991/12/18  20:26:30  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16. #include "console.h"
  17.  
  18. static struct msg_struct    **create_msg_list();
  19. static void            display_msg_list();
  20.  
  21. extern struct procStatus    *create_status();
  22. extern char    *time_t2RFC(), *vol2str(), *time_t2str(), *cmd_argv[],
  23.     *mystrtotime(), *itoa();
  24. extern Level lev;
  25. extern int    info_shown, cmd_argc;
  26.  
  27. struct msg_struct    **msg_matches = NULL;
  28. int                msg_num_matches = 0;
  29. char            *msg_match = NULLCP;
  30.  
  31. struct msg_struct    **global_msg_list = NULL,
  32.             *find_msg();
  33. int            number_msgs = 0;
  34.  
  35. #define     MSG_READ_INTERVAL    60    /* in secs */
  36.  
  37. /* ARGSUSED */
  38. int do_readchannelmtamessage (ad, ds, args, arg)
  39. int                ad;
  40. struct client_dispatch        *ds;
  41. char                **args; 
  42. /* args[0] = chan args[1] = mta or name in case of local chan */
  43. struct type_Qmgr_MsgRead    **arg;
  44. {
  45.     char    *str;
  46.     UTC    utc;
  47.  
  48.     *arg = (struct type_Qmgr_MsgRead *) malloc(sizeof(**arg));
  49.     bzero ((char *) *arg, sizeof(**arg));
  50.     /* fillin time */
  51.     utc = (UTC) malloc (sizeof(struct UTCtime));
  52.  
  53.     utc->ut_flags = UT_SEC;
  54.     utc->ut_sec = MSG_READ_INTERVAL;
  55.     str = utct2str(utc);
  56.     (*arg)->time = str2qb(str, strlen(str), 1);
  57.     if (args[0] != NULLCP)
  58.         (*arg)->channel = str2qb(args[0], strlen(args[0]), 1);
  59.     if (args[1] != NULLCP)
  60.         (*arg)->mta = str2qb(args[1], strlen(args[1]), 1);
  61.  
  62. }
  63.  
  64. /* ARGSUSED */
  65. int readchannelmtamessage_result (ad, id, dummy, result, roi)
  66. int                        ad,
  67.                         id,
  68.                         dummy;
  69. register struct type_Qmgr_MsgList        *result;
  70. struct RoSAPindication                *roi;
  71. {
  72.     free_msg_list();
  73.     global_msg_list = create_msg_list(result->msgs);
  74.     order_msgs();
  75.     return OK;
  76. }
  77.  
  78. extern struct chan_struct    *currentchan;
  79. extern struct mta_struct    *currentmta;
  80. extern int            connected;
  81.  
  82. msg_list()
  83. {
  84.     if (connected == TRUE
  85.         && currentchan != NULL
  86.         && currentmta != NULL) {
  87.         char    *args[2];
  88.         args[0] = currentchan->channelname;
  89.         args[1] = currentmta->mta;
  90.         my_invoke(readchannelmtamessage, args);
  91.         if (global_msg_list)
  92.             display_msg_list(global_msg_list, number_msgs);
  93.     }
  94. }
  95.  
  96. msg_do_refresh ()
  97. {
  98.     char    *args[2];
  99.     if (!connected)
  100.         return;
  101.     if (currentchan && currentmta) {
  102.         mta_do_refresh();
  103.         args[0] = currentchan->channelname;
  104.         args[1] = currentmta->mta;
  105.         my_invoke(readchannelmtamessage, args);
  106.         if (msg_match)
  107.             find_msg_regex(msg_match);
  108.         reset_prompt_regex();
  109.  
  110.         if (lev == msg) {
  111.             if (msg_num_matches > 0 && info_shown == TRUE)
  112.                 msg_info_regex();
  113.             else if (global_msg_list)
  114.                     display_msg_list(global_msg_list, 
  115.                              number_msgs);
  116.         }
  117.     }
  118. }
  119.  
  120. /*   */
  121. extern int    uk_order;
  122. extern char    *reverse_adr();
  123. extern FILE *out;
  124.  
  125. static void display_msg(msg)
  126. struct msg_struct    *msg;
  127. {
  128.     char    str[BUFSIZ];
  129.     char    *ch1, *ch2;
  130.  
  131.     if (msg->reciplist == NULL
  132.         || msg->reciplist->next == NULL)
  133.         /* delivery report */
  134.         sprintf(str,"dr (%s) to %s",
  135.             msg->msginfo->queueid,
  136.             msg->msginfo->originator);
  137.     else {
  138.         struct recip    *ix = msg->reciplist;
  139.         int        found = 0;
  140.  
  141.         while (ix != NULL && found == 0) {
  142.             if (ix->actChan != NULL 
  143.                 && currentchan != NULL 
  144.                 && strcmp(ix->actChan, 
  145.                       currentchan->channelname) == 0) {
  146.                 /* channel matches */
  147.                 if (is_loc_chan(currentchan) == TRUE) { 
  148.                     if (ix->recipient && currentmta
  149.                         && strcmp(ix->recipient, currentmta->mta) == 0)
  150.                         found = 1;
  151.                 } else if (ix->mta != NULL 
  152.                        && currentmta != NULL
  153.                        && strcmp(ix->mta, 
  154.                              currentmta->mta) == 0)
  155.                     /* mta matches */
  156.                     found = 1;
  157.             }
  158.             if (found == 0)
  159.                 ix = ix->next;
  160.         }
  161.         if (ix != NULL && ix->id == 0) {
  162.             /* delivery report ? */
  163.             ch1 = (uk_order) ? reverse_adr(ix -> recipient)
  164.                 : ix -> recipient;
  165.             sprintf(str, "dr (%s) to %s",
  166.                 msg->msginfo->queueid,
  167.                 ch1);
  168.             if (uk_order && ch1 != ix -> recipient) free(ch1);
  169.         } else {
  170.             if (ix == NULL) ix = msg->reciplist->next;
  171.  
  172.             ch1 = (uk_order) ? reverse_adr(ix -> recipient) : ix -> recipient;
  173.             ch2 = (uk_order) ? reverse_adr(msg->msginfo->originator) : msg->msginfo->originator;
  174.  
  175.             sprintf(str, "%s to %s from %s",
  176.                 msg->msginfo->queueid,
  177.                 ch1, ch2);
  178.             if (uk_order) {
  179.                 if (ch1 != ix -> recipient) free(ch1);
  180.                 if (ch2 != msg->msginfo->originator) free(ch2);
  181.             }
  182.         }
  183.     }
  184.  
  185.     fprintf(out, "%s\n", str);
  186. }
  187.  
  188. display_msg_info(msg)
  189. struct msg_struct    *msg;
  190. {
  191.     struct recip    *ix;
  192.     char        *str, *ch,
  193.             *info_str,
  194.             temp[BUFSIZ];
  195.     int        info_strlen = BUFSIZ;
  196.     info_str = calloc(1, BUFSIZ);
  197.  
  198.     sprintf(temp, "%s", msg->msginfo->queueid);
  199.     resize_info_str(&info_str, &info_strlen, strlen(temp)+1);
  200.     sprintf(info_str, "%s\n", temp);
  201.  
  202.     ch = (uk_order) ? reverse_adr(msg->msginfo->originator) 
  203.         : msg->msginfo->originator;
  204.     sprintf(temp, ssformat, tab, "originator ", ch);
  205.     if (uk_order && ch != msg->msginfo->originator) free(ch);
  206.     resize_info_str(&info_str, &info_strlen, strlen(temp+1));
  207.     sprintf(info_str, "%s%s\n", info_str, temp);
  208.  
  209.     if (msg->msginfo->size != 0) {
  210.         char    size[BUFSIZ];
  211.         
  212.         if (msg->msginfo->size > 1000000)
  213.             (void) sprintf(size, "%.2f M",
  214.                        (double) (msg->msginfo->size)/1000000.0);
  215.         else if (msg->msginfo->size > 1000)
  216.             (void) sprintf(size, "%.2f k",
  217.                        (double) (msg->msginfo->size)/1000.0);
  218.         else
  219.             (void) sprintf(size, "%d bytes", 
  220.                        msg -> msginfo -> size);
  221.         sprintf(temp, ssformat, tab,
  222.             "size", size);
  223.         resize_info_str(&info_str, &info_strlen, strlen(temp)+1);
  224.         sprintf(info_str, "%s%s\n", info_str, temp);
  225.     }
  226.     if (msg->msginfo->uaContentId != NULLCP) {
  227.         sprintf(temp, ssformat, tab,
  228.             "ua content id",
  229.             msg->msginfo->uaContentId);
  230.         resize_info_str(&info_str, &info_strlen, strlen(temp)+1);
  231.         sprintf(info_str, "%s%s\n", info_str, temp);
  232.     }
  233.  
  234.     if (msg->msginfo->inChannel != NULLCP) {
  235.         sprintf(temp, ssformat, tab,
  236.             "inbound channel",
  237.             msg->msginfo->inChannel);
  238.         resize_info_str(&info_str, &info_strlen, strlen(temp)+1);
  239.         sprintf(info_str, "%s%s\n", info_str, temp);
  240.     }
  241.     
  242.     ix = msg->reciplist;
  243.     if (ix != NULL) ix = ix->next;
  244.     while (ix != NULL) {
  245.         sprintf(info_str, "%s\n", info_str);
  246.         ch = (uk_order) ? reverse_adr(ix -> recipient) 
  247.             : ix -> recipient;
  248.         sprintf(temp, ssformat, tab,
  249.             "to",
  250.             ch);
  251.         if (uk_order && ch != ix -> recipient) free(ch);
  252.  
  253.         sprintf(temp, "%s(id %d)", temp, ix->id);
  254.  
  255.         if (ix->info != NULLCP)
  256.             sprintf(temp, plus_ssformat, temp, tab,
  257.                 "error info",
  258.                 ix -> info);
  259.  
  260.         if (ix->chansOutstanding == NULL)
  261.             sprintf(temp, plus_ssformat, temp, tab,
  262.                 "",
  263.                 "awaiting DRs");
  264.         else
  265.             sprintf(temp, plus_ssformat, temp, tab,
  266.                 "remaining channels",
  267.                 ix->chansOutstanding);
  268.         if (ix->status->cachedUntil != 0) {
  269.             str = time_t2RFC(ix->status->cachedUntil);
  270.             sprintf(temp, plus_ssformat, temp, tab,
  271.                 "delayed until",
  272.                 str);
  273.             free(str);
  274.         }
  275.         sprintf(temp, plus_ssformat, temp, tab,
  276.             "status",
  277.             (ix->status->enabled == TRUE) ? "enabled" : "disabled");
  278.         
  279.         if (ix->status->lastAttempt != 0) {
  280.             str = time_t2RFC(ix->status->lastAttempt);
  281.             sprintf(temp, plus_ssformat, temp, tab,
  282.                 "last attempt",
  283.                 str);
  284.             free(str);
  285.         }
  286.  
  287.         if (ix->status->lastSuccess != 0) {
  288.             str = time_t2RFC(ix->status->lastSuccess);
  289.             sprintf(temp, plus_ssformat, temp, tab,
  290.                 "last success",
  291.                 str);
  292.             free(str);
  293.         }
  294.         resize_info_str(&info_str, &info_strlen, strlen(temp)+1);
  295.         sprintf(info_str, "%s%s\n", info_str, temp);
  296.         ix = ix->next;
  297.     }
  298.     sprintf(info_str, "%s\n", info_str);
  299.  
  300.     temp[0] = '\0';
  301.     if (msg->msginfo->contenttype != NULLCP) 
  302.         sprintf(temp, plus_ssformat, temp, tab,
  303.             "content type",
  304.             msg->msginfo->contenttype);
  305.  
  306.     if (msg->msginfo->eit != NULL)
  307.         sprintf(temp, plus_ssformat, temp, tab,
  308.             "eits",
  309.             msg->msginfo->eit);
  310.     str = time_t2str(time((time_t *) 0) - msg->msginfo->age);
  311.     sprintf(temp, plus_ssformat, temp, tab,
  312.         "Age",
  313.         str);
  314.     free(str);
  315.     if (msg->msginfo->expiryTime != 0) {
  316.         str = time_t2RFC(msg->msginfo->expiryTime);
  317.         sprintf(temp, plus_ssformat, temp, tab,
  318.             "Expiry time",
  319.             str);
  320.         free(str);
  321.     }
  322.     if (msg->msginfo->deferredTime != 0) {
  323.         str = time_t2RFC(msg->msginfo->deferredTime);
  324.         sprintf(temp, plus_ssformat, temp, tab,
  325.             "Deferred until",
  326.             str);
  327.         free(str);
  328.     }
  329.     switch (msg->msginfo->priority) {
  330.         case int_Qmgr_Priority_low:
  331.         sprintf(temp, plus_ssformat, temp, tab,
  332.             "priority",
  333.             "low");
  334.         break;
  335.         case int_Qmgr_Priority_normal:
  336.         sprintf(temp, plus_ssformat, temp, tab,
  337.             "priority",
  338.             "normal");
  339.         break;
  340.         case int_Qmgr_Priority_high:
  341.         sprintf(temp, plus_ssformat, temp, tab,
  342.             "priority",
  343.             "high");
  344.         break;
  345.         default:
  346.         break;
  347.     }
  348.     if (msg->msginfo->errorCount != 0)
  349.         sprintf(temp, plus_sdformat, temp, tab,
  350.             "number of errors",
  351.             msg->msginfo->errorCount);
  352.     resize_info_str(&info_str, &info_strlen, strlen(temp));
  353.     sprintf(info_str, "%s%s", info_str, temp);
  354.  
  355.     fprintf(out, "%s", info_str);
  356.     free(info_str);
  357. }
  358.  
  359.  
  360. msg_info_regex()
  361. {
  362.     int    i;
  363.     if (msg_num_matches > 0) {
  364.         openpager();
  365.         if (msg_num_matches > 1)
  366.             fprintf(out, "%s: %d matches\n\n",
  367.                 msg_match, msg_num_matches);
  368.         for (i = 0; i < msg_num_matches; i++) {
  369.             display_msg_info(msg_matches[i]);
  370.             fprintf(out, "\n");
  371.         }
  372.         closepager();
  373.     }
  374. }
  375.  
  376. static void display_msg_list(list, num)
  377. struct msg_struct    **list;
  378. int            num;
  379. {
  380.     int    i;
  381.     openpager();
  382.  
  383.     for (i = 0;i < num; i++)
  384.         display_msg(list[i]);
  385.     closepager();
  386. }
  387.  
  388. msg_force_list(list, num)
  389. struct msg_struct    **list;
  390. int            num;
  391. {
  392.     int    i;
  393.     for (i = 0;i < num; i++)
  394.         msg_force(list[i]);
  395. }
  396.  
  397. /*   */
  398. static char    *create_eits(eit)
  399. struct type_Qmgr_EncodedInformationTypes    *eit;
  400. {
  401.     struct type_Qmgr_EncodedInformationTypes *ix;
  402.     char    *str,
  403.         buf[BUFSIZ];
  404.     int    first;
  405.     if (eit == NULL)
  406.         return NULL;
  407.     ix =eit;
  408.     first = TRUE;
  409.  
  410.     while (ix != NULL) {
  411.         str = qb2str(ix->PrintableString);
  412.         if (first == TRUE) {
  413.             sprintf(buf,"%s",str);
  414.             first = FALSE;
  415.         } else 
  416.             sprintf(buf,"%s, %s",buf, str);
  417.         free(str);
  418.         ix = ix->next;
  419.     }
  420.     return strdup(buf);
  421. }
  422.  
  423. static struct permsginfo    *create_msginfo(info)
  424. struct type_Qmgr_PerMessageInfo    *info;
  425. {
  426.     struct permsginfo    *temp;
  427.  
  428.     temp = (struct permsginfo *) calloc(1,sizeof(*temp));
  429.  
  430.     temp->queueid = qb2str(info->queueid);
  431.     temp -> originator = qb2str(info->originator);
  432.     if (info->contenttype != NULL)
  433.         temp->contenttype = qb2str(info->contenttype);
  434.     else
  435.         temp->contenttype = NULL;
  436.     temp->eit = create_eits(info->eit);
  437.     temp->age = convert_time(info->age);
  438.     temp->size = info->size;
  439.     temp->priority = info->priority->parm;
  440.     if (info->expiryTime == NULL)
  441.         temp->expiryTime = 0;
  442.     else
  443.         temp->expiryTime = convert_time(info->expiryTime);
  444.     if (info->deferredTime == NULL)
  445.         temp->deferredTime = 0;
  446.     else 
  447.         temp->deferredTime = convert_time(info->deferredTime);
  448.     if (info->optionals & opt_Qmgr_PerMessageInfo_errorCount)
  449.         temp->errorCount = info->errorCount;
  450.     if (info->inChannel != NULL)
  451.         temp->inChannel = qb2str(info->inChannel);
  452.     else
  453.         temp->inChannel = NULLCP;
  454.     if (info->uaContentId != NULL)
  455.         temp -> uaContentId = qb2str(info->uaContentId);
  456.     else
  457.         temp -> uaContentId = NULLCP;
  458.     return temp;
  459. }
  460.  
  461. static char            *create_chans(list, done, pfirst)
  462. struct type_Qmgr_ChannelList    *list;
  463. int                done;
  464. char                **pfirst;
  465. {
  466.     int    count;
  467.     char    buf[BUFSIZ],
  468.         *str;
  469.  
  470.     struct type_Qmgr_ChannelList    *ix;
  471.     count = 0;
  472.     ix = list;
  473.     while (count < done && ix != NULL) {
  474.         ix = ix->next;
  475.         count++;
  476.     }
  477.     if (ix == NULL)
  478.         /* all done waiting for delivery notifcation */
  479.         return NULL;
  480.  
  481.     str = qb2str(ix->Channel);
  482.     sprintf(buf,"%s",str);
  483.     free(str);
  484.     *pfirst = qb2str(ix->Channel);
  485.     ix = ix->next;
  486.  
  487.     while (ix != NULL) {
  488.         str = qb2str(ix->Channel);
  489.         sprintf(buf, "%s, %s",buf,str);
  490.         free(str);
  491.         ix = ix->next;
  492.     }
  493.     return strdup(buf);
  494. }
  495.     
  496. static struct recip        *create_recip(recip)
  497. struct type_Qmgr_RecipientInfo    *recip;
  498. {
  499.     struct recip    *temp;
  500.  
  501.     temp = (struct recip *) calloc(1,sizeof(*temp));
  502.  
  503.     temp->id = recip->id->parm;
  504.  
  505.     temp -> recipient = qb2str(recip->user);
  506.     temp->mta = qb2str(recip->mta);
  507.     temp->chansOutstanding = create_chans(recip->channelList,
  508.                           recip->channelsDone,
  509.                           &temp->actChan);
  510.     temp->status = create_status(recip->procStatus);
  511.     if (recip -> info != NULL)
  512.         temp -> info = qb2str (recip -> info);
  513.     return temp;
  514. }
  515.     
  516.     
  517. static struct recip         *create_reciplist(list)
  518. struct type_Qmgr_RecipientList    *list;
  519. {
  520.     struct recip    *head = NULL,
  521.             *tail = NULL,
  522.             *temp;
  523.  
  524.     while (list != NULL) {
  525.         if (list->RecipientInfo->id != 0) {
  526.             temp = create_recip(list->RecipientInfo);
  527.             if (head == NULL)
  528.                 tail = head = temp;
  529.             else {
  530.                 tail->next = temp;
  531.                 tail = temp;
  532.             }
  533.         }
  534.         list = list->next;
  535.     }
  536.     return head;
  537. }
  538.  
  539. static struct msg_struct    *create_msg(msg)
  540. struct type_Qmgr_MsgStruct    *msg;
  541. {
  542.     struct msg_struct    *temp;
  543.     
  544.     temp = (struct msg_struct *) calloc(1, sizeof(*temp));
  545.     temp->msginfo = create_msginfo(msg->messageinfo);
  546.     temp->reciplist = create_reciplist(msg->recipientlist);
  547.     add_tailor_to_msg(currentchan, temp);
  548.     return temp;
  549. }
  550.  
  551. static struct msg_struct    **create_msg_list(list)
  552. struct type_Qmgr_MsgStructList    *list;
  553. {
  554.     struct type_Qmgr_MsgStructList    *ix = list;
  555.     struct msg_struct        **msglist;
  556.     int                i;
  557.     number_msgs = 0;
  558.     while (ix != NULL) {
  559.         number_msgs++;
  560.         ix = ix->next;
  561.     }
  562.  
  563.     msglist = (struct msg_struct **) calloc((unsigned) number_msgs, 
  564.                         sizeof(struct msg_struct *));
  565.     
  566.     ix = list;
  567.     i = 0;
  568.     while ((ix != NULL)
  569.            & (i < number_msgs)) {
  570.         msglist[i] = create_msg(ix->MsgStruct);
  571.         i++;
  572.         ix = ix->next;
  573.     }
  574.     return msglist;
  575. }
  576.  
  577. clear_msg_level()
  578. {
  579.     free_msg_list();
  580.     if (msg_matches) {
  581.         free(msg_matches);
  582.         msg_matches = NULL;
  583.     }
  584.     msg_num_matches = 0;
  585. }
  586.  
  587. free_msg_list()
  588. {
  589.     int i = 0;
  590.     if (global_msg_list == NULL || number_msgs == 0)
  591.         return;
  592.  
  593.     while (i < number_msgs) {
  594.         free_permsginfo(global_msg_list[i]->msginfo);
  595.         free_reciplist(global_msg_list[i]->reciplist);
  596.         i++;
  597.     }
  598.     free((char *) global_msg_list);
  599.     global_msg_list = NULL;
  600.     number_msgs = 0;
  601. }
  602.  
  603. free_permsginfo(info)
  604. struct permsginfo    *info;
  605. {
  606.     free(info->queueid);
  607.     free(info->originator);
  608.     if (info->eit != NULL) free(info->eit);
  609.     if (info->inChannel != NULL) free(info->inChannel);
  610.     if (info->uaContentId != NULLCP) free(info->uaContentId);
  611.     free((char *) info);
  612. }
  613.  
  614. free_reciplist(list)
  615. struct recip    *list;
  616. {
  617.     struct recip    *ix = list,
  618.             *temp;
  619.  
  620.     while (ix != NULL) {
  621.         if (ix->recipient) free(ix->recipient);
  622.         if (ix->mta != NULL) free(ix->mta);
  623.         if (ix->actChan != NULL) free(ix->actChan);
  624.         if (ix->chansOutstanding != NULL) free(ix->chansOutstanding);
  625.         if (ix -> info != NULL) free(ix->info);
  626.         free((char *) ix->status);
  627.         temp = ix;
  628.         ix = ix->next;
  629.         free((char *) temp);
  630.     }
  631. }
  632.  
  633. /*   */
  634.  
  635. struct recip    *find_recip(msg, id)
  636. struct msg_struct    *msg;
  637. int            id;
  638. {
  639.     struct recip    *ix;
  640.     if (msg == NULL)
  641.         return NULL;
  642.     ix = msg->reciplist;
  643.     
  644.     while (ix != NULL
  645.            && ix -> id != id)
  646.         ix = ix->next;
  647.     return ix;
  648. }
  649.  
  650. struct msg_struct *find_msg(qid)
  651. char    *qid;
  652. {
  653.     int    i = 0;
  654.  
  655.     while ((i < number_msgs) &&
  656.            (strcmp(global_msg_list[i]->msginfo->queueid,qid) != 0))
  657.         i++;
  658.  
  659.     if (i >= number_msgs)
  660.         return NULL;
  661.     else
  662.         return global_msg_list[i];
  663. }
  664.  
  665. extern char    *re_comp();
  666. extern int    re_exec();
  667.  
  668. int    find_msg_regex(name)
  669. char    *name;
  670. {
  671.     int    i = 0;
  672.     char    *diag;
  673.  
  674.     if ((diag = re_comp(name)) != 0) {
  675.         fprintf(stderr,
  676.             "re_comp error for '%s' [%s]\n", name, diag);
  677.         return 0;
  678.     }
  679.     
  680.     if (msg_matches) {
  681.         free(msg_matches);
  682.         msg_matches = NULL;
  683.     }
  684.  
  685.     msg_matches = (struct msg_struct **) calloc(number_msgs,
  686.                            sizeof(struct msg_struct *));
  687.  
  688.     for (i = 0, msg_num_matches = 0; i < number_msgs; i++) 
  689.         if (re_exec(lowerfy(global_msg_list[i]->msginfo->queueid)) == 1) 
  690.             msg_matches[msg_num_matches++] = global_msg_list[i];
  691.  
  692.     return msg_num_matches;
  693. }
  694.  
  695. msg_set_current_regex()
  696. {
  697.     int    cont = TRUE, quit = FALSE, first = TRUE;
  698.     char    buf[BUFSIZ];
  699.  
  700.     while (cont == TRUE) {
  701.         if (cmd_argc > 1 && first == TRUE) {
  702.             strcpy(buf, cmd_argv[1]);
  703.             first = FALSE;
  704.         } else {
  705.             fprintf(stdout, "match expression (%s) (q=quit) = ", 
  706.                 (msg_match == NULLCP) ? "" : msg_match);
  707.             fflush(stdout);
  708.  
  709.             if (gets(buf) == NULL)
  710.                 exit (OK);
  711.         }
  712.         compress(buf, buf);
  713.         
  714.         if (emptyStr(buf) && msg_match == NULLCP)
  715.             fprintf(stdout, "no match set\n");
  716.         else {
  717.             if (!emptyStr(buf)) {
  718.                 if (lexequ(buf, "q") != 0) {
  719.                     if (msg_match) free(msg_match);
  720.                     msg_match = strdup(buf);
  721.                 } else
  722.                     quit = TRUE;
  723.             }
  724.             cont = FALSE;
  725.         }
  726.     }
  727.     if (quit == TRUE)
  728.         return NOTOK;
  729.     if (find_msg_regex(msg_match) == 0) {
  730.         fprintf(stdout, "unable to find match for '%s'\n",
  731.             msg_match);
  732.         return NOTOK;
  733.     }
  734.     return OK;
  735. }
  736.  
  737. msg_set_current()
  738. {
  739.     int    cont = TRUE, i, quit = FALSE, first = TRUE;
  740.     char    buf[BUFSIZ];
  741.  
  742.     while (cont == TRUE) {
  743.         if (cmd_argc > 1 && first == TRUE) {
  744.             strcpy(buf, cmd_argv[1]);
  745.             first = FALSE;
  746.         } else {
  747.             fprintf(stdout, "match expression (%s) (q=quit) = ", 
  748.                 (msg_match == NULL) ? "" : msg_match);
  749.             fflush(stdout);
  750.  
  751.             if (gets(buf) == NULL)
  752.                 exit (OK);
  753.         }
  754.         compress(buf, buf);
  755.         
  756.         if (emptyStr(buf) && msg_match == NULLCP)
  757.             fprintf(stdout, "no match set\n");
  758.         else if (!emptyStr(buf) && lexequ(buf, "q") == 0) {
  759.             quit = TRUE;
  760.             cont = FALSE;
  761.         } else {
  762.             char    *exp = (emptyStr(buf)) ? msg_match : buf;
  763.             int num = find_msg_regex(exp);
  764.             switch (num) {
  765.                 case 0:
  766.                 fprintf(stdout, "unable to find match for '%s'\n", exp);
  767.                 break;
  768.                 case 1:
  769.                 cont = FALSE;
  770.                 if (exp != msg_match) {
  771.                     if (msg_match) free(msg_match);
  772.                     msg_match = strdup(exp);
  773.                 }
  774.                 break;
  775.                 default:
  776.                 fprintf(stdout, "'%s' matches %d possible msgs (",
  777.                     exp, num);
  778.                 for (i = 0; i < num; i++)
  779.                     fprintf(stdout, "%s%s",
  780.                         msg_matches[i]->msginfo->queueid,
  781.                         (i == num -1) ? "" : ",");
  782.                 fprintf(stdout, ")\n\tneed unqiue msg\n");
  783.                 break;
  784.             }
  785.         }
  786.     }
  787.     if (quit == TRUE)
  788.         return NOTOK;
  789.     return OK;
  790. }
  791.  
  792. /*   */
  793.  
  794. msg_next()
  795. {
  796.     if (global_msg_list) {
  797.         int i = 0;
  798.         
  799.         if (msg_num_matches > 0) {
  800.             while (i < number_msgs &&
  801.                    msg_matches[0] != global_msg_list[i])
  802.                 i++;
  803.             if (i >= number_msgs - 1)
  804.                 i = 0;
  805.             else
  806.                 i++;
  807.         }
  808.         if (msg_match) free(msg_match);
  809.         msg_match = strdup(global_msg_list[i]->msginfo->queueid);
  810.         find_msg_regex(msg_match);
  811.     }
  812. }
  813.  
  814. msg_previous()
  815. {
  816.     if (global_msg_list) {
  817.         int i = number_msgs - 1;
  818.         
  819.         if (msg_num_matches > 0) {
  820.             while (i <= 0 &&
  821.                    msg_matches[0] != global_msg_list[i])
  822.                 i--;
  823.             if (i <= 0)
  824.                 i = number_msgs - 1;
  825.             else
  826.                 i--;
  827.         }
  828.         if (msg_match) free(msg_match);
  829.         msg_match = strdup(global_msg_list[i]->msginfo->queueid);
  830.         find_msg_regex(msg_match);
  831.     }
  832. }
  833.  
  834. /*   */
  835.  
  836.  
  837. msg_control(op, msg, usrs, mytime)
  838. Operations    op;
  839. char        *msg, *usrs, *mytime;
  840. {
  841.  
  842.     /* arg1 = QID arg2 = time arg3 = control arg4.. = userlist */
  843.     char    *usrlist[100], **args;
  844.     int    numberUsrs, i = 0, ix;
  845.  
  846.     numberUsrs = sstr2arg(usrs, 100, usrlist, ",");
  847.     
  848.     args = (char **) calloc((unsigned)(4+numberUsrs), sizeof(char *));
  849.     args[0] = msg;
  850.     args[1] = mytime;
  851.     args[2] = (char *) op;
  852.     ix = 3;
  853.     while(i < numberUsrs && ix < (3+numberUsrs)) 
  854.         args[ix++] = usrlist[i++];
  855.     my_invoke(op, args);
  856.     free((char *) args);
  857. }
  858.  
  859. msg_enable_regex()
  860. {
  861.     int    cont, i = 0, ucont;
  862.     char    buf[BUFSIZ], users[BUFSIZ];
  863.     users[0] = '\0';
  864.     
  865.     if (msg_num_matches > 0) {
  866.         if (msg_num_matches > 1)
  867.             fprintf(stdout, "%s: %d matches\n\n",
  868.                 msg_match, msg_num_matches);
  869.         for (i = 0; i < msg_num_matches; i++) {
  870.             cont = TRUE;
  871.             while (cont == TRUE) {
  872.                 if (msg_num_matches == 1) {
  873.                     fprintf(stdout, "enabling '%s'.\n",
  874.                         msg_matches[i]->msginfo->queueid);
  875.                     buf[0] = 'y';
  876.                 } else {
  877.                     fprintf(stdout, "enable '%s' (y/n/q) ?",
  878.                         msg_matches[i]->msginfo->queueid);
  879.                     fflush(stdout);
  880.                     if (gets(buf) == NULL)
  881.                         exit(OK);
  882.                     compress(buf, buf);
  883.                 }
  884.                 switch(buf[0]) {
  885.                     case 'y':
  886.                     case 'Y':
  887.                     ucont = TRUE;
  888.                     while (ucont == TRUE) {
  889.                         fprintf(stdout, "User list (,) (*=all) = ");
  890.                         fflush(stdout);
  891.                         if (gets(buf) == NULL)
  892.                             exit (OK);
  893.                         compress(buf, buf);
  894.                         if (emptyStr(buf)) {
  895.                             if (users[0] != '\0')
  896.                                 ucont = FALSE;
  897.                             else 
  898.                                 fprintf(stdout, "no user list given\n");
  899.                         } else {
  900.                             ucont = FALSE;
  901.                             strcpy(users, buf);
  902.                         }
  903.                     }
  904.                     msg_control(msgstart,
  905.                             msg_matches[i]->msginfo->queueid, 
  906.                             users, NULLCP);
  907.                     case 'n':
  908.                     case 'N':
  909.                     cont = FALSE;
  910.                     break;
  911.                     case 'q':
  912.                     case 'Q':
  913.                     cont = FALSE;
  914.                     i = msg_num_matches;
  915.                     default:
  916.                     break;
  917.                 }
  918.             }
  919.         }
  920.     }
  921. }
  922.  
  923. msg_disable_regex()
  924. {
  925.     int    cont, i = 0, ucont;
  926.     char    buf[BUFSIZ], users[BUFSIZ];
  927.     users[0] = '\0';
  928.     
  929.     if (msg_num_matches > 0) {
  930.         if (msg_num_matches > 1)
  931.             fprintf(stdout, "%s: %d matches\n\n",
  932.                 msg_match, msg_num_matches);
  933.         for (i = 0; i < msg_num_matches; i++) {
  934.             cont = TRUE;
  935.             while (cont == TRUE) {
  936.                 if (msg_num_matches == 1) {
  937.                     fprintf(stdout, "disabling '%s'.\n",
  938.                         msg_matches[i]->msginfo->queueid);
  939.                     buf[0] = 'y';
  940.                 } else {
  941.                     fprintf(stdout, "disable '%s' (y/n/q) ?",
  942.                         msg_matches[i]->msginfo->queueid);
  943.                     fflush(stdout);
  944.                     if (gets(buf) == NULL)
  945.                         exit(OK);
  946.                     compress(buf, buf);
  947.                 }
  948.                 switch(buf[0]) {
  949.                     case 'y':
  950.                     case 'Y':
  951.                     ucont = TRUE;
  952.                     while (ucont == TRUE) {
  953.                         fprintf(stdout, "User list (,) (*=all) = ");
  954.                         fflush(stdout);
  955.                         if (gets(buf) == NULL)
  956.                             exit (OK);
  957.                         compress(buf, buf);
  958.                         if (emptyStr(buf)) {
  959.                             if (users[0] != '\0')
  960.                                 ucont = FALSE;
  961.                             else 
  962.                                 fprintf(stdout, "no user list given\n");
  963.                         } else {
  964.                             ucont = FALSE;
  965.                             strcpy(users, buf);
  966.                         }
  967.                     }
  968.                     msg_control(msgstop,
  969.                             msg_matches[i]->msginfo->queueid, 
  970.                             users, NULLCP);
  971.                     case 'n':
  972.                     case 'N':
  973.                     cont = FALSE;
  974.                     break;
  975.                     case 'q':
  976.                     case 'Q':
  977.                     cont = FALSE;
  978.                     i = msg_num_matches;
  979.                     default:
  980.                     break;
  981.                 }
  982.             }
  983.         }
  984.     }
  985. }
  986.  
  987.  
  988. msg_clear_regex()
  989. {
  990.     int    cont, i = 0, ucont;
  991.     char    buf[BUFSIZ], users[BUFSIZ];
  992.     users[0] = '\0';
  993.     
  994.     if (msg_num_matches > 0) {
  995.         if (msg_num_matches > 1)
  996.             fprintf(stdout, "%s: %d matches\n\n",
  997.                 msg_match, msg_num_matches);
  998.         for (i = 0; i < msg_num_matches; i++) {
  999.             cont = TRUE;
  1000.             while (cont == TRUE) {
  1001.                 if (msg_num_matches == 1) {
  1002.                     fprintf(stdout, "clearing '%s'.\n",
  1003.                         msg_matches[i]->msginfo->queueid);
  1004.                     buf[0] = 'y';
  1005.                 } else {
  1006.                     fprintf(stdout, "clear '%s' (y/n/q) ?",
  1007.                         msg_matches[i]->msginfo->queueid);
  1008.                     fflush(stdout);
  1009.                     if (gets(buf) == NULL)
  1010.                         exit(OK);
  1011.                     compress(buf, buf);
  1012.                 }
  1013.                 switch(buf[0]) {
  1014.                     case 'y':
  1015.                     case 'Y':
  1016.                     ucont = TRUE;
  1017.                     while (ucont == TRUE) {
  1018.                         fprintf(stdout, "User list (,) (*=all) = ");
  1019.                         fflush(stdout);
  1020.                         if (gets(buf) == NULL)
  1021.                             exit (OK);
  1022.                         compress(buf, buf);
  1023.                         if (emptyStr(buf)) {
  1024.                             if (users[0] != '\0')
  1025.                                 ucont = FALSE;
  1026.                             else 
  1027.                                 fprintf(stdout, "no user list given\n");
  1028.                         } else {
  1029.                             ucont = FALSE;
  1030.                             strcpy(users, buf);
  1031.                         }
  1032.                     }
  1033.                     msg_control(msgclear,
  1034.                             msg_matches[i]->msginfo->queueid, 
  1035.                             users, NULLCP);
  1036.                     case 'n':
  1037.                     case 'N':
  1038.                     cont = FALSE;
  1039.                     break;
  1040.                     case 'q':
  1041.                     case 'Q':
  1042.                     cont = FALSE;
  1043.                     i = msg_num_matches;
  1044.                     default:
  1045.                     break;
  1046.                 }
  1047.             }
  1048.         }
  1049.     }
  1050. }
  1051.  
  1052. msg_clear_above_regex()
  1053. {
  1054.     int    cont, i = 0, above = FALSE;
  1055.     char    buf[BUFSIZ];
  1056.     
  1057.     if (msg_num_matches > 0) {
  1058.         if (msg_num_matches > 1)
  1059.             fprintf(stdout, "%s: %d matches\n\n",
  1060.                 msg_match, msg_num_matches);
  1061.         for (i = 0; i < msg_num_matches; i++) {
  1062.             cont = TRUE;
  1063.             while (cont == TRUE) {
  1064.                 if (msg_num_matches == 1) {
  1065.                     fprintf(stdout, "clearing entities above '%s'.\n",
  1066.                         msg_matches[i]->msginfo->queueid);
  1067.                     buf[0] = 'y';
  1068.                 } else {
  1069.                     fprintf(stdout, "clear entities above '%s' (y/n/q) ?",
  1070.                         msg_matches[i]->msginfo->queueid);
  1071.                     fflush(stdout);
  1072.                     if (gets(buf) == NULL)
  1073.                         exit(OK);
  1074.                     compress(buf, buf);
  1075.                 }
  1076.                 switch(buf[0]) {
  1077.                     case 'y':
  1078.                     case 'Y':
  1079.                     msg_force(msg_matches[i]);
  1080.                     above = TRUE;
  1081.                     case 'n':
  1082.                     case 'N':
  1083.                     cont = FALSE;
  1084.                     break;
  1085.                     case 'q':
  1086.                     case 'Q':
  1087.                     cont = FALSE;
  1088.                     i = msg_num_matches;
  1089.                     default:
  1090.                     break;
  1091.                 }
  1092.             }
  1093.         }
  1094.         if (above == TRUE)
  1095.             mta_clear_above_regex();
  1096.     }
  1097. }
  1098.  
  1099. msg_force (msg)
  1100. struct msg_struct    *msg;
  1101. {
  1102.     char    **args = NULL;
  1103.  
  1104.     int    numberUsrs = 0, force;
  1105.     int    ix;
  1106.     struct recip    *temp;
  1107.     if (msg == NULL
  1108.         || msg->msginfo == NULL) return;
  1109.  
  1110.     for (temp = msg->reciplist, numberUsrs = 0; 
  1111.          temp != NULL; temp = temp -> next, numberUsrs++)
  1112.         continue;
  1113.  
  1114.     args = (char **) calloc((unsigned)(4+numberUsrs), sizeof(char *));
  1115.     args[0] = msg->msginfo->queueid;
  1116.     args[1] = NULL;
  1117.  
  1118.     ix = 3;
  1119.     force = FALSE;
  1120.     for (temp = msg->reciplist; temp != NULL; temp = temp -> next)
  1121.         if (temp->status
  1122.             && temp->status->enabled != TRUE) {
  1123.             args[ix++] = itoa(temp->id);
  1124.             force = TRUE;
  1125.         }
  1126.     if (force == TRUE) {
  1127.         args[ix] = NULLCP;
  1128.         args[2] = (char *) msgstart;
  1129.         my_invoke(msgstart, args);
  1130.     }
  1131.  
  1132.     ix = 3;
  1133.     force = FALSE;
  1134.  
  1135.     for (temp = msg->reciplist; temp != NULL; temp = temp -> next)
  1136.         if (temp->status
  1137.             && temp->status->cachedUntil != 0) {
  1138.             args[ix++] = itoa(temp->id);
  1139.             force = TRUE;
  1140.         }
  1141.     if (force == TRUE) {
  1142.         args[ix] = NULLCP;
  1143.         args[2] = (char *) msgclear;
  1144.         my_invoke(msgstart, args);
  1145.     }
  1146.     for (ix = 3; args[ix] != NULLCP && ix < 4+numberUsrs; ix++)
  1147.         free (args[ix]);
  1148.     free((char *) args);
  1149. }    
  1150.  
  1151. msg_delay_regex()
  1152. {
  1153.     int    cont, i = 0, ucont, dcont;
  1154.     char    buf[BUFSIZ], users[BUFSIZ], delay[BUFSIZ];
  1155.     users[0] = '\0';
  1156.     delay[0] = '\0';
  1157.     
  1158.     if (msg_num_matches > 0) {
  1159.         if (msg_num_matches > 1)
  1160.             fprintf(stdout, "%s: %d matches\n\n",
  1161.                 msg_match, msg_num_matches);
  1162.         for (i = 0; i < msg_num_matches; i++) {
  1163.             cont = TRUE;
  1164.             while (cont == TRUE) {
  1165.                 if (msg_num_matches == 1) {
  1166.                     fprintf(stdout, "delaying '%s'.\n",
  1167.                         msg_matches[i]->msginfo->queueid);
  1168.                     buf[0] = 'y';
  1169.                 } else {
  1170.                     fprintf(stdout, "delay '%s' (y/n/q) ?",
  1171.                         msg_matches[i]->msginfo->queueid);
  1172.                     fflush(stdout);
  1173.                     if (gets(buf) == NULL)
  1174.                         exit(OK);
  1175.                     compress(buf, buf);
  1176.                 }
  1177.                 switch(buf[0]) {
  1178.                     case 'y':
  1179.                     case 'Y':
  1180.                     ucont = TRUE;
  1181.                     while (ucont == TRUE) {
  1182.                         fprintf(stdout, "User list (,) (*=all) = ");
  1183.                         fflush(stdout);
  1184.                         if (gets(buf) == NULL)
  1185.                             exit (OK);
  1186.                         compress(buf, buf);
  1187.                         if (emptyStr(buf)) {
  1188.                             if (users[0] != '\0')
  1189.                                 ucont = FALSE;
  1190.                             else 
  1191.                                 fprintf(stdout, "no user list given\n");
  1192.                         } else {
  1193.                             ucont = FALSE;
  1194.                             strcpy(users, buf);
  1195.                         }
  1196.                     }
  1197.                     dcont = TRUE;
  1198.                     while (dcont == TRUE) {
  1199.                         fprintf(stdout, "Delay (in s m h d and/or w) = ");
  1200.                         fflush(stdout);
  1201.  
  1202.                         if (gets(buf) == NULL)
  1203.                             exit (OK);
  1204.                         compress(buf, buf);
  1205.                         if (emptyStr(buf)) {
  1206.                             if (delay[0] != '\0')
  1207.                                 dcont = FALSE;
  1208.                             else 
  1209.                                 fprintf(stdout, "no user list given\n");
  1210.                         } else {
  1211.                             dcont = FALSE;
  1212.                             strcpy(delay, buf);
  1213.                         }
  1214.                     }
  1215.                     msg_control(msgcacheadd,
  1216.                             msg_matches[i]->msginfo->queueid, 
  1217.                             users, delay);
  1218.                     case 'n':
  1219.                     case 'N':
  1220.                     cont = FALSE;
  1221.                     break;
  1222.                     case 'q':
  1223.                     case 'Q':
  1224.                     cont = FALSE;
  1225.                     i = msg_num_matches;
  1226.                     default:
  1227.                     break;
  1228.                 }
  1229.             }
  1230.         }
  1231.     }
  1232. }
  1233.  
  1234. struct type_Qmgr_UserList    *create_userlist(qid, argv)
  1235. char    *qid,
  1236.     **argv;
  1237. {
  1238.     struct type_Qmgr_UserList    *temp,
  1239.                     *head = NULL,
  1240.                     *tail = NULL;
  1241.     int                i = 0;
  1242.     struct msg_struct        *msg;
  1243.     struct recip            *ix;
  1244.  
  1245.     if (strcmp(argv[i], "*") == 0) {
  1246.         if ((msg = find_msg(qid)) == NULL)
  1247.             return NULL;
  1248.         ix = msg -> reciplist;
  1249.         while (ix != NULL) {
  1250.             temp = (struct type_Qmgr_UserList *) 
  1251.                 calloc (1, sizeof(*temp));
  1252.             temp->RecipientId = (struct type_Qmgr_RecipientId *) 
  1253.                 malloc(sizeof(struct type_Qmgr_RecipientId));
  1254.             temp->RecipientId->parm = ix -> id;
  1255.             ix = ix -> next;
  1256.             if (head == NULL)
  1257.                 head = tail = temp;
  1258.             else {
  1259.                 tail->next = temp;
  1260.                 tail = tail->next;
  1261.             }
  1262.         }
  1263.     } else {
  1264.         while (argv[i] != NULL) {
  1265.             temp = (struct type_Qmgr_UserList *) 
  1266.                 calloc (1, sizeof(*temp));
  1267.             temp->RecipientId = (struct type_Qmgr_RecipientId *) 
  1268.                 malloc(sizeof(struct type_Qmgr_RecipientId));
  1269.             temp->RecipientId->parm = atoi(argv[i++]);
  1270.         
  1271.             if (head == NULL)
  1272.                 head = tail = temp;
  1273.             else {
  1274.                 tail->next = temp;
  1275.                 tail = tail->next;
  1276.             }
  1277.         }
  1278.     }
  1279.     return head;
  1280. }
  1281.  
  1282. /* ARGSUSED */
  1283. int do_msgcontrol (ad, ds, args, arg)
  1284. int                ad;
  1285. struct client_dispatch        *ds;
  1286. char                **args;
  1287. struct type_Qmgr_MsgControl    **arg;
  1288. /* args[0] = qid */
  1289. /* args[1] = time */
  1290. /* args[2] = stop, start, clear cacheadd*/
  1291. /* args[3..] = NULL terminated list of users */
  1292. {
  1293.     char    *timestr;
  1294.     *arg = (struct type_Qmgr_MsgControl *) malloc(sizeof(**arg));
  1295.     
  1296.     (*arg)->qid = str2qb(args[0],
  1297.                  strlen(args[0]),
  1298.                  1);
  1299.  
  1300.     (*arg)->users = create_userlist(args[0], &(args[3]));
  1301.  
  1302.     (*arg)->control = (struct type_Qmgr_Control *)
  1303.         malloc(sizeof(struct type_Qmgr_Control));
  1304.  
  1305.     switch ((Operations) args[2]) {
  1306.         case msgstart:
  1307.         (*arg)->control->offset = type_Qmgr_Control_start;
  1308.         break;
  1309.         case msgstop:
  1310.         (*arg)->control->offset = type_Qmgr_Control_stop;
  1311.         break;
  1312.         case msgclear:
  1313.         (*arg)->control->offset = type_Qmgr_Control_cacheClear;
  1314.         break;
  1315.         case msgcacheadd:
  1316.         (*arg)->control->offset = type_Qmgr_Control_cacheAdd;
  1317.         timestr = mystrtotime(args[1]);
  1318.         (*arg)->control->un.cacheAdd = str2qb(timestr,strlen(timestr),1);
  1319.         free(timestr);
  1320.         break;
  1321.         default:
  1322.         PP_LOG(LLOG_EXCEPTIONS,
  1323.                ("console : '%s' unknown control param for msgs",
  1324.             args[1]));
  1325.         return NOTOK;
  1326.     }
  1327.     return OK;
  1328. }
  1329.  
  1330. /* ARGSUSED */
  1331. msgcontrol_result (sd, id, dummy, result, roi)
  1332. int                    sd,
  1333.                                     id,
  1334.                                     dummy;
  1335. struct type_Qmgr_Pseudo__newmessage     *result;
  1336. struct RoSAPindication            *roi;
  1337. {
  1338.     return OK;
  1339. }
  1340.